#include "Sensor.h"
#include "Box.h"
#include "ShareComponents.h"
#include "Camera.h"
#include "Box.h"
#include "Sprite.h"
#include "MainGame.h"
#include "GunWeapon.h"
#include "RSManager.h"

Sensor::Sensor(Box* box, BULLET_ID gunWeapon_id): Object(box,ObjEnemy_STATIC)
{
	_gunWeapon_id =gunWeapon_id;
}
Sensor::~Sensor(void)
{

}
void Sensor::init()
{
	_sprite= RSManager::getInstance()->getSprite(SENSOR);
	_isAlive=true;
	_hits=1;
	delay=0;
	delay_time =200;
}
void Sensor::update()
{
	if(gl_camera->getRightSide()>_box->_position.x+_box->_size.x + 60){
			if(gl_camera->getLeftSide()>_box->_position.x -10){
				_sprite->Reset(0);
			}
	else{
				
		delay+=GAME_TIME;
		if(_sprite->_index==1) delay_time= 60;
		else delay_time=400;
		if(delay>delay_time){
			delay=0;
			_sprite->Next();
				
			}
		if(_sprite->_index==2 && _hits<=0){
			_isAlive=false;
			GunWeapon* gunWeapon =new GunWeapon
			(new Box(_box->_position,D3DXVECTOR2(48,30),D3DXVECTOR2(3,0)),_gunWeapon_id);
			gunWeapon->init();
			gl_MainGame->addWorldObject(gunWeapon);
			}
		}
			
	}
}
	
void Sensor::render()
{
	if(_isAlive)
		_sprite->Render(_box->_position);
}

Box* Sensor::getCollisionBox()
{
	_colBox->_position=_box->_position+ D3DXVECTOR2(15,15);
	_colBox->_size=_box->_size/2;
	_colBox->_v = _box->_v;
	return _colBox;
}
